﻿#pragma once

#include "lp_init.h"
#include "lp_storage.h"

enum {
    LP_PTYPE_SEND,
    LP_PTYPE_RESP,
    LP_PTYPE_TIMEOUT,
    LP_PTYPE_SOCKET,
};

typedef struct LPMsg LPMsg;
struct LPMsg {
    int ptype;
    int cmd;
    void* ud;
    LPService from;
    LPService self;
    LPSession session;
    void* data;
    size_t size;
    void (*free)(LPMsg*);
};

typedef struct {
    int ptype;
    int cmd;
    LPSession session;
    void* data;
    size_t size;
    void (*free)(LPMsg*);
}LPMsgSend;

typedef void (*LPExitSvrCallback)(LPService h, void* ud);
typedef void (*LPMsgCallback)(LPMsg* msg);


LP_API int
lpInitServiceContext ();

LP_API int
lpExitServiceContext ();

LP_API LPService
lpNewService (LPMsgCallback cb, void* ud);

LP_API int
lpDispatchService (LPService h);

LP_API int
lpDispatchWorker ();

LP_API int
lpAttachWorker (LPService h);

LP_API int
lpSend (LPService h, LPMsgSend* send);

LP_API int
lpNewSession (LPService h, LPSession* session);

